/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.pb.sistcomp.dao;

import br.pb.sistcomp.entity.Leilao;
import java.util.List;
import javax.persistence.EntityManager;
import br.pb.sistcomp.util.HibernateUtil;
import java.util.ArrayList;
import java.util.Date;

/**
 *
 * @author jefferson
 */
public class LeilaoDaoImpl implements LeilaoDao {

    private EntityManager em = HibernateUtil.getInstance().getFactory().createEntityManager();

    @Override
    public void addLeilao(Leilao leilao) {

        em.getTransaction().begin();

        em.persist(leilao);
        
        em.getTransaction().commit();

    }

    @Override
    public Leilao removeLeilao(Leilao leilao) {
        
        em.getTransaction().begin();
        
        em.remove(leilao);
        
        em.getTransaction().commit();

        return leilao;

    }

    @Override
    public List<Leilao> listarTodos() {
        return em.createQuery("SELECT c FROM leiloes c").getResultList();
    }

    @Override
    public List<Leilao> listarTodosAtivos() {
       
       return em.createQuery("SELECT l FROM leiloes l WHERE status = 'Ativo'").getResultList();

    }

    @Override
    public List<Leilao> listarTodosInativos() {
       
       return em.createQuery("SELECT l FROM leiloes l WHERE status = 'Inativo'").getResultList();
   }

    @Override
    //Faltar implementar a lógica do retorno
    public List<Leilao> listarFaltaUmaHora() {

        return em.createQuery("SELECT l FROM leiloes l WHERE hora = 'umahora'").getResultList();

    }
}
